package throughtester

import (
	"fmt"
	"net"
	"time"

	"gitee.com/sillyman/pcaphelper/pktbuilder"
)

// TestEthernet 发射和捕获以太网包，如果能捕获到发射的数据包，则返回nil
func (t *throughTester) TestEthernet(src, dst net.HardwareAddr, timeout time.Duration) error {
	t.maybeLetNetworkLearnMe(dst)

	if err := t.tx.WritePacketData(pktbuilder.BuildingEtherPkt(src, dst, nil)); err != nil {
		return err
	}

	bpfExpr := fmt.Sprintf("ether dst %s and ether src %s and ether proto %#X", dst, src, int(pktbuilder.CustomEthType))
	return t.rx.CanCaptureIncoming(timeout, bpfExpr)
}
